<template>
  <el-card>
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <el-select
          v-model="categoryStore.C1Id"
          @change="getC2"
          :disabled="scene == 1"
        >
          <el-option
            v-for="C1 in categoryStore.C1Arr"
            :key="C1.id"
            :label="C1.name"
            :value="C1.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          v-model="categoryStore.C2Id"
          @change="getC3"
          :disabled="scene == 1"
        >
          <el-option
            v-for="C2 in categoryStore.C2Arr"
            :key="C2.id"
            :label="C2.name"
            :value="C2.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="categoryStore.C3Id" :disabled="scene == 1">
          <el-option
            v-for="C3 in categoryStore.C3Arr"
            :key="C3.id"
            :label="C3.name"
            :value="C3.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
import useCategoryStore from '@/store/modules/category'
import { onMounted } from 'vue'
//接收来自父组件的数据
defineProps(['scene'])
const categoryStore = useCategoryStore()
// let C1Arr = ref<any>(undefined)
// let C1Id= ref<number>(undefined)

//获取三个分类的数据
const getC1 = async () => {
  await categoryStore.getC1()
}
const getC2 = async () => {
  categoryStore.C2Id = ''
  categoryStore.C3Id = ''
  categoryStore.C3Arr = []
  await categoryStore.getC2()
}
const getC3 = async () => {
  categoryStore.C3Id = ''
  await categoryStore.getC3()
}
//挂载时获取第一个分类数据
onMounted(async () => {
  await getC1()
})
</script>

<style scoped></style>
